#include <bits/stdc++.h>
using namespace std;
int T,n,m,L,V,d[1000005],v[100005],p[1000005],p1[1000005],a[100005],flag=0;
inline int read()
{
    int x=0,f=1;
    char c=getchar();
    while((c<'0' || c>'9') && c!='-')   c=getchar();
    if(c=='-')  f=f*-1,c=getchar();
    while(c>='0' && c<='9')
    {
        x=x*10+c-'0';
        c=getchar();
    }
    return x*f;
}
void init(int j,int k)
{
    for(int i=1;i<=k;i++)
        p[i]=p1[i]=0;
    for(int i=1;i<=j;i++)
        d[i]=v[i]=a[i]=0;
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--)
    {
        n=read();m=read();L=read();V=read();
        for(int i=1;i<=n;i++)
        {
            d[i]=read();v[i]=read();a[i]=read();
            if(a[i]!=0) flag=1;
        }
        for(int i=1;i<=m;i++)
        {
            p[i]=read();
        }
        sort(p+1,p+1+m);
        //cout<<p[1]<<"!!!!!!!"<<endl;
        if(flag==0)//shi yun su
        {
            int ans1=0,ans2=0;
            for(int i=1;i<=n;i++)
            {
                if(v[i]>V)//chao su
                {
                    auto it=lower_bound(p+1,p+1+m,d[i]);
                    //cout<<d[i]<<" ";
                    int pos=distance(p,it);//no wrong
                    //cout<<pos<<"!!!!!!!!!!!!   "<<*(p+m);
                    if(pos>=0 && d[i]<=*(p+m))
                    {
                        ans1++;
                        p1[pos]=1;
                    }
                }
            }
            for(int i=1;i<=m;i++)
            {
                if(p1[i]==1)  ans2++;
            }
            init(n,m);
            printf("%d %d\n",ans1,m-ans2);
        }
    }
    return 0;
}
